package cis.android.signlocker.data;

import android.util.Xml;

import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;

import cis.android.signlocker.signableview.SignDataRow;

/**
 * Created by MaiHoàng on 20/03/2014.
 */
public class XmlSignData {
    public static String SignDataToXml(ArrayList<SignDataRow> signData) throws IOException {
        XmlSerializer serializer = Xml.newSerializer();
        StringWriter writer = new StringWriter();
        serializer.setOutput(writer);
        serializer.startDocument("UTF-8", true);
        serializer.startTag("", "sign_data");

        for (SignDataRow row : signData) {
            serializer.startTag("", "sign");

            serializer.startTag("", "time");
            serializer.text(Long.toString(row.getTime()));
            serializer.endTag("", "time");

            serializer.startTag("", "position");
            serializer.attribute("", "x", Float.toString(row.getX()));
            serializer.attribute("", "y", Float.toString(row.getY()));
            serializer.endTag("", "position");

            serializer.endTag("", "sign");
        }

        serializer.endTag("", "sign_data");
        serializer.endDocument();

        return writer.toString();
    }
}
